<%@page contentType="text/html;charset=utf-8" language="java"
	import="java.util.*,com.pub.database.*"%>
<% response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); %>
<% response.setHeader("Cache.Control","no-cache"); response.setHeader("Pragma","no-cache"); response.setDateHeader("Expires",0);%>
<jsp:useBean id="webFunction" scope="request"
	class="com.pub.web.WebFunction" />
<!-- 以下為DataView 共用設定 -->
<jsp:useBean id="DataViewForm" scope="request"
	class="com.pub.database.DataViewForm" />
<jsp:setProperty name="DataViewForm" property="pageRowCount" value="10" />
<jsp:setProperty name="DataViewForm" property="nowPageNum" />
<jsp:setProperty name="DataViewForm" property="submitMethod"
	value="POST" />
<jsp:setProperty name="DataViewForm" property="dataViewAction" />
<jsp:setProperty name="DataViewForm" property="filterCol" />
<jsp:setProperty name="DataViewForm" property="filterValue" />
<jsp:setProperty name="DataViewForm" property="dvOrderByFields" />
<jsp:setProperty name="DataViewForm" property="dvOrderBySeq" />
<!-- DataView 設定結束 -->

<% webFunction.setPortal_to_session(request); //set session from portal
   ResourceBundle lrbdWEB_Config = ResourceBundle.getBundle("WEB_Config",Locale.getDefault());
   com.pub.database.DataView DataView=new com.pub.database.DataView(lrbdWEB_Config.getString("DB_ALIAS"),
                            Boolean.valueOf(lrbdWEB_Config.getString("DEBUG")).booleanValue(),
                            lrbdWEB_Config.getString("SOURCE_CHARSET"),
                            lrbdWEB_Config.getString("TARGET_CHARSET"));
   String strSysNO="";
   String sqlcmd="";
   String groupuser="";
   String lstrOnloadScript="";
   QueryBean qbnDAO = new QueryBean(lrbdWEB_Config.getString("DB_ALIAS"), Boolean.valueOf(lrbdWEB_Config.getString("DEBUG")).booleanValue(), lrbdWEB_Config.getString("SOURCE_CHARSET"), lrbdWEB_Config.getString("TARGET_CHARSET"));
   if(request.getParameter("sys_no")!=null && !request.getParameter("sys_no").trim().equals("")){
     strSysNO=request.getParameter("sys_no").trim().toLowerCase();



   }
     ArrayList<ArrayList<Object>> rs=qbnDAO.querySQL("select sys_manager from wkf_sys_owner  where sys_no='"+strSysNO+"'");
       if (rs!=null){
            for (int i=0;i<rs.size();i++){
               groupuser+= rs.get(i).toString().replace("[", "").replace("]", "")+",";
            }
      }

   if(request.getParameter("prgAction")!=null && request.getParameter("prgAction").trim().equals("add")){
     if(request.getParameter("empno")!=null && !request.getParameter("empno").trim().equals("")){
       sqlcmd="insert into wkf_sys_owner (sys_no,sys_manager) values ('"+ strSysNO+"','"+ request.getParameter("empno").trim()+"')";
       qbnDAO.executeSQL(sqlcmd);
       rs=qbnDAO.querySQL("select sys_manager from wkf_sys_owner  where sys_no='"+strSysNO+"'");
       if (rs!=null){
            groupuser="";
            for (int i=0;i<rs.size();i++){
               groupuser+= rs.get(i).toString().replace("[", "").replace("]", "")+",";
            }
      }
       lstrOnloadScript = "window.returnValue='" + groupuser + "';window.close();";
     }
   }

   if(request.getParameter("prgAction")!=null && request.getParameter("prgAction").trim().equals("delete")){
        String sn=request.getParameter("rowsn")!=null ?request.getParameter("rowsn").trim():"";
        String delsys_no=request.getParameter("sysno_"+sn)!=null ? request.getParameter("sysno_"+sn).trim():"";
        String delempno=request.getParameter("empno_"+sn)!=null ? request.getParameter("empno_"+sn):"";
        sqlcmd="delete from wkf_sys_owner where sys_no='"+delsys_no+"' and sys_manager='"+delempno+"'";
        qbnDAO.executeSQL(sqlcmd);


   }

if (session.getAttribute("u_id")==null) {
   session.setAttribute("path",String.valueOf(request.getRequestURI()));
   session.setAttribute("param",null);
   response.sendRedirect("/SWD/login.jsp?prg_no=/SWD/pages/pub/set_sysowner.jsp" + strSysNO);return; } %>

<%
try{
    String strFromSQL="";
    String strWhereSQL="";
    String strdbf_no="";
    String strdbf_name="";
    DataViewForm.setFieldsList("'',sys_no,sys_manager");
    strFromSQL="wkf_sys_owner";
    strWhereSQL="sys_no='"+strSysNO+"' ";
    DataViewForm.setTablesList(strFromSQL);
    DataViewForm.setSQLCondition(strWhereSQL);
    DataViewForm.setCountSQL("select count(*) from " + strFromSQL + " where " + strWhereSQL);
    DataViewForm.setPageActionURI("set_sysowner.jsp?sys_no=" + strdbf_no );

    boolean blnDebug=false;
    String strColRelation[][]=new String[3][];

    strColRelation[0]=new String[5];
    strColRelation[1]=new String[5];
    strColRelation[2]=new String[5];


    strColRelation[0][0] = "''";
    strColRelation[0][1] = "INPUT";
    strColRelation[0][2] = "WIDTH='10%' align='center'";
    strColRelation[0][3] = "<INPUT class='button b_normal' TYPE=\"BUTTON\" onclick=\"javascript:saveRowSn('%sn%');document.all('prgAction').value='delete';document.forms[0].submit();\" NAME=\"del\" VALUE=";
    strColRelation[0][4] = "'刪除'";

    strColRelation[1][0]="'系統編號'";
    strColRelation[1][1]="INPUT";
    strColRelation[1][2]="WIDTH='10%' ";
    strColRelation[1][3]="<INPUT TYPE='text' size='20' name='sysno_%sn%' CLASS='input_noborder'  VALUE=";
    strColRelation[1][4]="1";

    strColRelation[2][0]="'維護名稱'";
    strColRelation[2][1]="INPUT";
    strColRelation[2][2]="WIDTH='10%' ";
    strColRelation[2][3]="<INPUT TYPE='text' size='20' name='empno_%sn%' CLASS='input_noborder' VALUE=";
    strColRelation[2][4]="2";


    DataViewForm.setColRelation(strColRelation);
    DataViewForm.setPageBtnOnTop(true);
    DataViewForm.setPageBtnOnButtom(false);
    DataViewForm.setFilterShow(false);
    DataViewForm.setJumpPageShow(true);
    DataViewForm.setRowsInfoShow(true);
    DataViewForm.setRowPageShow(true);
    DataViewForm.setExcelShow(false);
    DataViewForm.setOrderEnable(false);
    DataViewForm.setTableDataTrHtml("onmouseover=\"this.className='td_content_ov" +
                                    "er'\" onmouseout=\"this.className='td_content'\"");//設定每筆TR的Html
    DataViewForm.setTableHeaderHtml("class='td_head_grid' align='center'");
%>
<html>

<head>
<script language="javascript" type="text/javascript">
   function saveRowSn(rowsn){
       if(document.all('rowsn').value.indexOf(rowsn)>-1){
          return;//已記錄過就不再記錄了
       }
       if(document.all('rowsn').value==''){
         document.all('rowsn').value=rowsn;
       } else{
         document.all('rowsn').value=document.all('rowsn').value + ',' + rowsn;
       }
    }
    function fc_exit(){
     var temp='<%=groupuser%>';
    window.returnValue=temp;
    window.close();
    //opener.location.href=opener.location.href;
  //  opener.location.href="/SWD/pages/basic/system_name_maintain.jsp?sys_no="+document.all("sys_no").value;

    }


</script>

<title></title>
<LINK HREF="/SWD/workflow.css" REL="stylesheet" TYPE="text/css">
<base target='_self' />
</head>
<body>
<form action="set_sysowner.jsp" method="POST">
<table>
	<tr>
		<th>工號：</th>
		<td><input type="text" name="empno" size="30" maxlength="30"
			class="input" /><input type="button"
			onclick="javascript:document.all('prgAction').value='add';document.forms[0].submit();"
			value="加入" /> <input type="button" onclick="javascript:fc_exit()"
			value="離開" /></td>
	</tr>

</table>
<INPUT TYPE="HIDDEN" NAME="sys_no"
	VALUE="<%=request.getParameter("sys_no")!=null ?request.getParameter("sys_no").trim():"" %>" />
<INPUT TYPE="HIDDEN" NAME="rowsn" /> <INPUT TYPE="HIDDEN"
	NAME="prgAction" /> <%DataView.OutputDataView(DataViewForm, pageContext);%>
</form>
</body>
</html>
<%
}catch(Exception e){
  e.printStackTrace();
}finally{
  lrbdWEB_Config=null;
}
%>


